<template>
	<view class="jiaoyi-detail">
		<u-navbar back-text=" " :title="title">
		</u-navbar>
		<!-- 返回首页 -->
		<uni-bankhome />
		<view class="wrapper-tabs">
			<swiper class="swiper-box" :current="swiperCurrent">
				<swiper-item class="swiper-item" v-for="index in list.length" :key="index">
					<scroll-view class="scroll-v view-wrapper" enableBackToTop="true" scroll-with-animation scroll-y>
						<!-- @scrolltolower="loadMore"> -->
						<view v-if="datas.length!=0" class="view-item" v-for="(logItem, logIndex) in datas"
							:key="logIndex">
							<view class="view-item-detail" v-if="logItem.sn">
								<view class="-title">{{logItem.remark||''}}</view>
								<view class="-title">订单号：{{logItem.sn}}</view>
							</view>
							<view class="view-item-detail" v-else>
								<view class="-title">充值焕贝</view>
							</view>
							<view class="view-item-change" v-if="logItem.sn">
								<view class="-money green" v-if="
									userInfo.id===logItem.payee">
									+{{logItem.money | unitPrice}}
								</view>
								<view class="-money" v-else>
									-{{logItem.money | unitPrice}}
								</view>
								<view class="-time">{{logItem.createTime}}</view>
							</view>
							<view class="view-item-change" v-else>
								<view class="-money green">
									+{{logItem.yiBei | unitPrice}}
								</view>
								<view class="-time">{{logItem.createTime}}</view>
							</view>
						</view>
						<u-empty v-if="datas.length==0" mode="history" text="暂无记录" />
						<u-loadmore v-else bg-color='#f8f8f8' :status="status" />
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import {
		getUserRecharge,
		getWalletLog,
		getrevoke
	} from "@/api/members";
	import {
		getUserWallet
	} from "@/api/members";
	export default {
		data() {
			return {
				walletNum: 0,
				status: "nomore",
				current: 0,
				swiperCurrent: 0,
				userInfo: {}, //用户详情信息
				params: {
					pageNumber: 1,
					pageSize: 10,
					order: "desc",
				},
				datas: [], //遍历的数据集合
				rechargeList: "", //充值明细列表
				walletLogList: "", //钱包变动列表
				list: [{
					name: "预存款变动明细",
				}, ],
				title: ''
			};
		},
		onLoad(option) {
			this.userInfo = this.$options.filters.isLogin() || {}
			this.type = option.type
			if (this.type == 'RECHARGE') {
				this.title = '余额变动明细'
			}
			if (this.type == 'PROMOTE') {
				this.title = '推广余额明细'
			}
			if (this.type == 'SALE') {
				this.title = '销售明细'
			}
		},
		watch: {
			swiperCurrent(index) {
				this.swiperCurrent = index;
			},
		},
		async mounted() {
			this.getWallet();
			let result = await getUserWallet(); //预存款

			this.walletNum = result.data.result.memberWallet;
		},
		methods: {
			getWallet() {
				this.status = "loading";
				this.params.walletFlag = this.type
				getWalletLog(this.params).then((res) => {
					if (res.data.success) {
						if (res.data.result.length != 0) {
							this.datas.push(...res.data.result);
						}
						this.status = "nomore";
					}
				});
			},
			changed(index) {
				this.datas = [];
				this.swiperCurrent = index;
				this.params.pageNumber = 1;
				if (index == 0) {
					this.getWallet();
				} else {
					this.getWallet();
				}
			},

			loadMore() {
				this.params.pageNumber++;
				this.getWallet();
			},
			// 撤销
			revoke(row) {
				let parse = {
					applyId: row.id
				}
				uni.showModal({
					title: '撤销提示',
					content: '撤销当前提现申请后，金额将退回销售钱包',
					confirmText: '确定',
					cancelText: '取消',
					success: data => {
						if (data.confirm) {
							getrevoke(parse).then((res) => {
								if (res.data == true) {
									uni.showToast({
										title: "撤销成功",
										icon: "none",
									});
									setTimeout(() => {
										this.datas = [];
										this.getWallet()
									}, 1000)
								} else {
									uni.showToast({
										title: "撤销失败",
										icon: "none",
									});
								}
							});
						}
					}
				});
			}
		},
	};
</script>

<style lang="scss" scoped>
	.jiaoyi-detail {
		width: 100%;
		height: calc(100vh - 44px);

		.green {
			color: $aider-color-green !important;
		}

		.view-item {
			padding: 32rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.view-item-change {
			text-align: right;

			>.-money {
				font-size: 36rpx;
				color: $main-color;
				font-weight: bold;
			}

			>.-time {
				font-size: 22rpx;
				color: #999;
			}
		}

		.view-item-detail {
			line-height: 1.75;

			>.-title {
				font-size: 28rpx;
			}

			>.-number {
				font-size: 22rpx;
				color: #999;
			}
		}

		.submit-btn {
			line-height: 90rpx;
			text-align: center;

			color: #fff;
			background: $main-color;

			margin: 0 auto;
			height: 90rpx;
		}

		.operation {
			font-size: 32rpx;
			margin-right: 24rpx;
			color: rgb(96, 98, 102);
		}

		.swiper-item,
		.scroll-v {
			height: 100%;
		}

		.swiper-box {
			/* #ifndef H5 */
			height: calc(100vh - 200rpx);
			/* #endif */

			/* #ifdef H5 */
			height: calc(100vh - 288rpx);
			/* #endif */
		}


	}
</style>
